package com.ikun.admin.modules.auth.utils;

import com.ikun.common.result.Result;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 认证失败处理器
 */

@Component
public class UnauthEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest req, HttpServletResponse resp, AuthenticationException e) throws IOException, ServletException {
        Result<Object> error = new Result<>().error(ResponseCode.UNAUTH_ENTRYPOINT.getCode(), ResponseCode.UNAUTH_ENTRYPOINT.getMessage());
        ResponseUtils.sendResponse(resp, error);
    }
}
